package com.zy.activity.ext

import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
import com.zy.composeworld.base.adapter.BaseActivityAdapter
import com.zy.composeworld.base.adapter.BaseViewBindingItemAdapter
import com.zy.composeworld.base.bean.BaseMenuBean
import com.zy.activity.bean.BaseViewBindingItemBean

fun RecyclerView.setSimpleLinearData(
    vertical: Boolean = true, initData: ArrayList<BaseMenuBean>.() -> Unit
) {
    adapter = BaseActivityAdapter(ArrayList<BaseMenuBean>().apply { initData(this) })
    layoutManager = if (vertical) {
        LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
    } else {
        LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
    }
}


//便于控制每个item 自定义
fun RecyclerView.setLinearDataVB(
    vertical: Boolean = true,
    viewBinding: Class<out ViewBinding>,
    initData: ArrayList<BaseViewBindingItemBean>.() -> Unit
): BaseViewBindingItemAdapter {
    val tmpAdapter = BaseViewBindingItemAdapter(
        viewBinding,
        ArrayList<BaseViewBindingItemBean>().apply { initData(this) })
    adapter = tmpAdapter
    layoutManager = if (vertical) {
        LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
    } else {
        LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
    }
    return tmpAdapter
}


fun RecyclerView.setGridData(size: Int, initData: ArrayList<BaseMenuBean>.() -> Unit) {
    adapter = BaseActivityAdapter(ArrayList<BaseMenuBean>().apply { initData(this) })
    layoutManager = GridLayoutManager(context, size)
}